package controller;



import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.ejb.AsyncResult;
import javax.ejb.Asynchronous;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;


/**
 * Session Bean implementation class AsynchronousSessionBean
 */
@Stateless
@LocalBean
public class AsynchronousSessionBean implements AsynchronousSessionBeanRemote {

	private static Logger logger = Logger.getLogger(AsynchronousSessionBean.class.getName());

	/**
	 * Default constructor.
	 */
	public AsynchronousSessionBean() {
		// TODO Auto-generated constructor stub
	}
	
	@Asynchronous
	@Override
	public void slowMethod() {
		long startTime = System.currentTimeMillis();
		logger.info("incepe "+ this.getClass().getCanonicalName() + ".slowMethod()");
		
		try
		{
			Thread.sleep(10000);
		}
		catch (InterruptedException ex) {
			
			Logger.getLogger(AsynchronousSessionBean.class.getName()).log(Level.SEVERE,null,ex);
	
		}
		
		logger.info("se termina " + this.getClass().getCanonicalName() + ".slowMethod()");
		
		long endTime = System.currentTimeMillis();
		
		logger.info("executia a durat " + (endTime - startTime) + " milisecunde");
	}
	
	
	@Asynchronous
	@Override
	public Future<Long> slowMethodWithReturnValue() {
		try{
			Thread.sleep(15000);
		}
		catch(InterruptedException ex){
			Logger.getLogger(AsynchronousSessionBean.class.getName()).log(Level.SEVERE,null,ex);
		}
		return new AsyncResult<Long>(42L);
	}
}


